local assets =
{
    Asset("ANIM", "anim/power_knife.zip"),
    
}



local function OnThrown(inst, owner, target)
   
    inst.AnimState:PlayAnimation("idle", true)
   
end
local function OnHit(inst, owner, target)
    if owner == target or owner:HasTag("playerghost") then
        inst:DoTaskInTime(0, inst.Remove)
    end
    if target ~= nil and target:IsValid() and target.components.combat then
        local impactfx = SpawnPrefab("impact")
        if impactfx ~= nil then
            local follower = impactfx.entity:AddFollower()
            follower:FollowSymbol(target.GUID, target.components.combat.hiteffectsymbol, 0, 0, 0)
            impactfx:FacePoint(inst.Transform:GetWorldPosition())
        end
    end
    
    inst:DoTaskInTime(0, inst.Remove)
    
  
    

end

local function OnMiss(inst, owner, target)
  inst:DoTaskInTime(0, inst.Remove)
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)
    RemovePhysicsColliders(inst)

    inst.AnimState:SetBank("power_knife")
    inst.AnimState:SetBuild("power_knife")
    inst.AnimState:PlayAnimation("idle")
    inst.AnimState:SetRayTestOnBB(true)

    --inst:AddTag("thrown")

    --weapon (from weapon component) added to pristine state for optimization
    --inst:AddTag("weapon")

    --projectile (from projectile component) added to pristine state for optimization
    inst:AddTag("projectile")

    local swap_data = {sym_build = "swap_boomerang"}
    MakeInventoryFloatable(inst, "small", 0.18, {0.8, 0.9, 0.8}, true, -6, swap_data)

    inst.scrapbook_specialinfo = "BOOMERANG"

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    
    ------
    inst:AddComponent("projectile")
    inst.components.projectile:SetSpeed(16)
    inst.components.projectile:SetCanCatch(true)
    inst.components.projectile:SetOnThrownFn(OnThrown)
    inst.components.projectile:SetOnHitFn(OnHit)
    inst.components.projectile:SetOnMissFn(OnMiss)
    --inst.components.projectile:SetOnCaughtFn(OnCaught)
    MakeHauntableLaunch(inst)

    return inst
end

return Prefab("power_knife", fn, assets)
